Skip to content

fix(frontend): gate credits API calls behind buyCredits feature flag - #646

Closed
EmilFattakhov wants to merge 1 commit into
mainfrom
fix/credits-api-feature-flag-guard
Closed

fix(frontend): gate credits API calls behind buyCredits feature flag#646
EmilFattakhov wants to merge 1 commit into
mainfrom
fix/credits-api-feature-flag-guard

Conversation

@EmilFattakhov

Copy link
Copy Markdown
Member

The backend returns 404 for /credits/summary and /credits/batches/expiring when BUY_CREDITS_ACTIVE is disabled. SessionEnsurer was polling /credits/summary every 30 s and ExpiryWarningBanner was polling /credits/batches/expiring every 5 min for all authenticated users, flooding the console with 404 errors and adding unnecessary network overhead.

Both queries now use enabled: !!session?.data && !!features?.buyCredits so they only fire when the feature flag is actually on. ExpiryWarningBanner also gains the useUserStore import needed to read the flag.

The backend returns 404 for /credits/summary and /credits/batches/expiring
when BUY_CREDITS_ACTIVE is disabled. SessionEnsurer was polling /credits/summary
every 30 s and ExpiryWarningBanner was polling /credits/batches/expiring every
5 min for all authenticated users, flooding the console with 404 errors and
adding unnecessary network overhead.

Both queries now use `enabled: !!session?.data && !!features?.buyCredits` so
they only fire when the feature flag is actually on. ExpiryWarningBanner also
gains the useUserStore import needed to read the flag.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@netlify

netlify Bot commented Mar 31, 2026

Copy link
Copy Markdown

Deploy Preview for auto-drive-storage ready!

Name Link
🔨 Latest commit a07807b
🔍 Latest deploy log https://app.netlify.com/projects/auto-drive-storage/deploys/69cbff51469d9f0008ccbb01
😎 Deploy Preview https://deploy-preview-646--auto-drive-storage.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

export const ExpiryWarningBanner = () => {
const { api } = useNetwork();
const session = useContext(SessionContext);
const features = useUserStore((m) => m.features);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale persisted features can still cause 404 requests

Low Severity

ExpiryWarningBanner reads features from the Zustand store, which is persisted to localStorage and never cleared on logout (clearUser omits features). If buyCredits was previously true and the backend later disables the flag, the stale persisted value causes the query to fire on initial page load, producing the exact 404 this PR aims to prevent. SessionEnsurer avoids this by using the fresh useQuery result (which starts as undefined). The two components use inconsistent data sources for the same gating check.

Additional Locations (1)
Fix in Cursor Fix in Web

@EmilFattakhov

Copy link
Copy Markdown
Member Author

Closing down as not needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant